<script setup>
import {ref} from "vue";

const activeMenu = ref(0);
import {useRouter, useRoute} from "vue-router";

const router = useRouter();
const route = useRoute();
const itemName = ref()
const menu = ref([
  {
    name: "首页",
    path: "/tabus/index",
  },
  {
    name: "课堂分析",
    path: "/tabus/classroom-analysis",
  },
  {
    name: "课堂分析记录管理",
    path: "/tabus/classroom-analysis-records",
  },
  {
    name: "数据分析",
    children: [
      { name: "班级分析", path: "/tabus/class-analysis" },
      { name: "教师分析", path: "/tabus/teacher-analysis" },
    ]
  },
  {
    name: "课堂管理",
    children: [
      { name: "教师管理", path: "/tabus/teacher-manage" },
      { name: "班级管理", path: "/tabus/class-manage" },
      { name: "课程管理", path: "/tabus/course-manage" },
    ]
  },
  {
    name: "团队介绍",
    path: "/tabus/myIndex",
  }
]);
const changActiveMenu = (item, index) => {
  activeMenu.value = index;
  router.push(item.path);
  console.log(route)
};
</script>

<template>
  <div class="nav">
    <div class="nav-max">
      <div class="nav-left">
        <div class="logo">
          <img src="@/assets/tabus.jpg" style="width: 40px;height: 40px" alt="">
          <div>TABUS</div>
        </div>
        <div class="menu">
          <template v-for="(item,index) in menu" :key="index">
            <div v-if="!item.children" @click="changActiveMenu(item,index)">
              <div ref="itemName" class="menu-name" :class="item.path  === route.path ? 'active-menu' : ''">{{ item.name }}</div>
            </div>
            <div v-else class="menu-dropdown">
              <div class="menu-name">{{ item.name }}</div>
              <div class="dropdown-content">
                <div v-for="child in item.children" :key="child.path" class="dropdown-item" @click="changActiveMenu(child,index)">
                  {{ child.name }}
                </div>
              </div>
            </div>
          </template>
        </div>
      </div>
      <div class="nav-right">
        <div class="info-tx">T</div>
        <div class="info-name">TABUS-admin</div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.logo{
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #000;
}
.nav {
  height: 60px;
  background-color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .08);
  border-bottom: 1px solid #e3e5e7;
}

.nav-max {
  width: 1200px;
  display: flex;
  justify-content: space-between;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 30px;
}

.menu {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 20px;
  cursor: pointer;
}
.active-menu{
  color: #409eff;
  font-weight: 600;
}
.active-menu:after {
  content: '';
  display: block;
  height: 3px;
  border-radius: 1px;
  background: #409eff;
  -webkit-animation: myfirst 0.3s; /* Safari 与 Chrome */
  //transition:  0.3s;
  transform: translateY(-3px);
}
@keyframes myfirst {
  0% {
    width: 0px;
  }
  100% {
    width: 100%;
  }
}
.menu-name{
  height: 60px;
  line-height: 60px;
  color: #000;
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.info-tx {
  width: 40px;
  height: 40px;
  background-color: #00bd7e;
  border-radius: 50%;
  text-align: center;
  line-height: 40px;
  font-weight: 600;
  color: white;
  font-size: 18px;
}

.info-name {
  font-size: 18px;
  font-weight: 600;
  color: #000;
}

.menu-dropdown {
  position: relative;
}
.menu-dropdown .dropdown-content {
  display: none;
  position: absolute;
  top: 60px;
  left: 0;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border: 1px solid #e3e5e7;
  z-index: 100;
  min-width: 120px;
}
.menu-dropdown:hover .dropdown-content {
  display: block;
}
.dropdown-item {
  padding: 10px 20px;
  cursor: pointer;
  white-space: nowrap;
  color: #000;
}
.dropdown-item:hover {
  background: #f5f7fa;
  color: #409eff;
}
</style>